#pragma once
#include "../SGD Wrappers/SGD_Geometry.h"
#include "../SGD Wrappers/SGD_Color.h"
#include "RSLList .h"
#include "../SGD Wrappers/SGD_Handle.h"
#include <random>
#include <list>

class Entity;

struct Particle
{	
	float LifeCurr;
	float LifeEnd;
	SGD::Point Position;
	SGD::Color ColorCurr;
	SGD::Size ScaleCurr;
	float RotaionCurr;
	SGD::Vector VelocityCurr;
	void setPart(float startl, float endl, SGD::Color sc,float sr, SGD::Size ss,SGD::Vector sv)
	{
		LifeCurr = 0;
		LifeEnd = startl + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (endl - startl)));
		ColorCurr = sc;
		RotaionCurr = sr;
		ScaleCurr = ss;
		VelocityCurr = sv;
	}
	Particle() = default;
};

struct ParticleFlyweight
{
	SGD::HTexture image;
	float MinLife;
	float MaxLife;
	int ColorStartA;
	int ColorStartR;
	int ColorStartG;
	int ColorStartB;
	int ColorEndA;
	int ColorEndR;
	int ColorEndG;
	int ColorEndB;
	float RotationStart;
	float RotationChange;
	SGD::Size ScaleStart;
	SGD::Size ScaleChange;
	SGD::Vector VelocityStart;
	SGD::Vector VelocityChange;
};

enum EShape{Point, Line, Rect, Circle};
class Emitter
{
public:
	int EmitterID;
	Entity*owner;
	std::string name;
	SGD::Point Position;
	float Spread;
	bool looping;
	bool gravity;
	bool bursting;
	float gravpull;
	SGD::Point gravpos;
	EShape EmitterShape; //rect, circle, angle
	SGD::Size Size;
	ParticleFlyweight Flyweight;
	int NumParticles;
	float SpawnRate;
	std::list<Particle*> alive;
	std::list<Particle*> dead;
	//SLList<Particle> alive;
	//SLLIter<Particle> iter;
	bool complete = false;
	float waited;
	int count;

	Emitter() = default;
	virtual ~Emitter();
	void Init();
	void Update(float dt);
	void ShadowUpdate(int type, Entity*howner, float dt, Emitter*hook = nullptr);
	void Render();
	bool Done(){ return complete; }
};

